package org.sunyaxing.gitlab.gitlabaireview;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import org.gitlab4j.api.GitLabApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ClientConfiguration {
    private static final Logger log = LoggerFactory.getLogger(ClientConfiguration.class);
    @Value("${mr.gitHost:http://127.0.0.1}")
    private String gitHost;
    @Value("${mr.gitToken:11111}")
    private String gitToken;
    @Value("${mr.aiToken:11111}")
    private String aiToken;
    @Value("${mr.aiBaseUrl:http://127.0.0.1}")
    private String aiBaseUrl;

    @Bean
    public GitLabApi gitLabApi() {
        log.info("【GitLabApi】 {} {}", gitHost, gitToken);
        GitLabApi gitLabApi = new GitLabApi(gitHost, gitToken);
        gitLabApi.setIgnoreCertificateErrors(true);
        gitLabApi.enableRequestResponseLogging();
        return gitLabApi;
    }

    @Bean
    public OpenAIClient openAIClient() {
        log.info("【openAIClient】 {} {}", aiBaseUrl, aiToken);
        return OpenAIOkHttpClient.builder()
                .baseUrl(aiBaseUrl)
                .apiKey(aiToken)
                .build();
    }
}
